Sys.WebForms.PageRequestManagerServerErrorException: An entity object cannot be referenced by multiple instances of IEntityChangeTracker [closed]

Posted by Mingebag on Programmers See other posts from Programmers or by Mingebag
Published on 2012-12-04T13:39:14Z Indexed on 2012/12/04 17:19 UTC
Read the original article Hit count: 186

Filed under:
|
|

`Story:

I have a strange error when I try to save something I got this error message

An entity object cannot be referenced by multiple instances of IEntityChangeTracker.

I really don’t know what that is and why is it appear, it appears only when I try to save something my insert and update is working, only when I try to save something in db from my Telerik grid

if (this.annualVacationList != null)
    {
        List<AnnualVacation> vacationToSave = this.annualVacationList;
        IEnumerable<AnnualVacation> existing = paramUser.AnnualVacations;
        foreach (AnnualVacation toSave in vacationToSave)
        {
            AnnualVacation existingItem = existing.Where(x => x.AnnualVacationId == toSave.AnnualVacationId).SingleOrDefault();
            if (existingItem == null)
            {
                ctx.AddToAnnualVacations(toSave);
            }
            else
            {
                existingItem.FromDate = toSave.FromDate;
                existingItem.ToDate = toSave.ToDate;
                existingItem.WorkingTime = toSave.WorkingTime;
                existingItem.VacationDays = toSave.VacationDays;
            }
        }
    }
    ctx.SaveChanges();
}

After debugging I have seen that the code brake down in the Project.Name.Designer.cs ..... O.o

 public void AddToAnnualVacations(AnnualVacation annualVacation)
    {
        base.AddObject("AnnualVacations", annualVacation);
    }

© Programmers or respective owner

Related posts about c#

Related posts about .NET